var slideIndex = 1;
  showSlides(slideIndex);

  function plusSlides(n) {
    showSlides(slideIndex += n);
  }

  function currentSlide(n) {
    showSlides(slideIndex = n);
  }

  function showSlides(n) {
    var i;
    var slides = document.getElementsByClassName("mySlides");
    var dots = document.getElementsByClassName("dot");
    if (n > slides.length) {slideIndex = 1}    
    if (n < 1) {slideIndex = slides.length}
    for (i = 0; i < slides.length; i++) {
        slides[i].style.display = "none";  
    }
    for (i = 0; i < dots.length; i++) {
        dots[i].className = dots[i].className.replace(" active", "");
    }
    slides[slideIndex-1].style.display = "block";  
    dots[slideIndex-1].className += " active";
  }

  var slideIndex = 0;
  carousel();

  function carousel() {
    var i;
    var x = document.getElementsByClassName("mySlides");
    var dots = document.getElementsByClassName("dot");
    for (i = 0; i < x.length; i++) {
      x[i].style.display = "none";
    }
    for (i = 0; i < dots.length; i++) {
      dots[i].className = dots[i].className.replace(" active", "");
    }
    slideIndex++;
    if (slideIndex > x.length) {
      slideIndex = 1;
    }
    x[slideIndex - 1].style.display = "block";
    dots[slideIndex - 1].className += " active";
    setTimeout(carousel, 2000); // 每 2 秒改变图片
  }

  //todolist

        const form = document.querySelector('#todo-form');
        const input = document.querySelector('#todo-input');
        const todoList = document.querySelector('#todo-list');
        const clearBtn = document.querySelector('#clear-btn');
        
        // 从本地缓存中获取待办事项列表
        let todos = JSON.parse(localStorage.getItem('todos')) || [];
        
        // 渲染待办事项列表
        function renderTodos() {
            // 清空ul元素的内容
            todoList.innerHTML = '';
        
            // 遍历todos数组，为每个元素创建一个li元素，并添加到ul元素中
            todos.forEach((todo, index) => {
                const li = document.createElement('li');
                li.textContent = todo;
                
                const deleteBtn = document.createElement('span');
                deleteBtn.textContent = '×';
                deleteBtn.classList.add('delete-btn');
                deleteBtn.addEventListener('click', () => deleteTodo(index));
                
                li.appendChild(deleteBtn);
                todoList.appendChild(li);
            });
        }
        
        // 添加待办事项
        function addTodo() {
            const todo = input.value.trim();
        
            if (todo) {
                todos.push(todo);
                localStorage.setItem('todos', JSON.stringify(todos));
                renderTodos();
                input.value = '';
            }
        }
        
        // 删除待办事项
        function deleteTodo(index) {
            todos.splice(index, 1);
            localStorage.setItem('todos', JSON.stringify(todos));
            renderTodos();
        }
        
        // 清空待办事项列表
        function clearTodos() {
            todos = [];
            localStorage.removeItem('todos');
            renderTodos();
        }
        
        // 绑定事件监听器
        form.addEventListener('submit', e => {
            e.preventDefault();
            addTodo();
        });
        
        clearBtn.addEventListener('click', clearTodos);
        
        // 初始化页面
        renderTodos();
        


